﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.model;

namespace l1cs.server.clientpackets
{
    public class C_SelectTarget : ClientBasePacket
    {
        private const String _C_SELECT_TARGET = "[C] C_SelectTarget";
        private static Logger _log = Logger.getLogger( typeof( C_SelectTarget ).FullName );

        public C_SelectTarget( byte[] abyte0, ClientThread clientthread )
            : base( abyte0 )
        {

            int petId = readD();
            int type = readC();
            int targetId = readD();

            L1PetInstance pet = (L1PetInstance)L1World.getInstance().findObject( petId );
            L1Character target = (L1Character)L1World.getInstance().findObject( targetId );

            if ( pet != null && target != null )
            {
                if ( target is L1PcInstance )
                {
                    L1PcInstance pc = (L1PcInstance)target;
                    if ( pc.checkNonPvP( pc, pet ) )
                    {
                        return;
                    }
                }
                pet.setMasterTarget( target );
            }
        }

        override
        public String getType()
        {
            return _C_SELECT_TARGET;
        }
    }
}